Enums in Rust

Metadata
aliases: [Enum in Rust]
shorthands: {}
created: 2022-06-17 11:37:46
modified: 2022-06-17 15:38:26

Enums are special in Rust, since each variant in the enum can have different types.

Example

For example, an arbitrary message type:

enum Message {
    Quit,
    Print(String),
    AddElement(ElementIndex),
    RemoveElement(ElementIndex),
    Move {x: f64, y: f64},
}

Where the Quit variant has no type, it just carries the information of it being the variant Quit. But the other variants all have other information with in them: